package com.zhangjie.apipassenger.controller;

import com.zhangjie.apipassenger.service.VerificationCodeService;
import com.zhangjie.internalcommon.dto.ResponseResult;
import com.zhangjie.internalcommon.request.VerificationCodeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: zj
 * @Date: 2024/1/19 - 01 - 19 - 16:40
 * @Description: com.zhangjie.apipassenger.controller
 * @version: 1.0
 */
@RestController
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    //@GetMapping("/verification-code")
    @PostMapping("/verification-code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){

        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        System.out.println("接收到的手机号参数："+passengerPhone);

        return verificationCodeService.generatorCode(passengerPhone);
    }

    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){

        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();

        System.out.println("手机号："+ passengerPhone +",验证码：" + verificationCode);

        return verificationCodeService.checkCode(passengerPhone, verificationCode);
    }
}
